package cn.Nodes;/*
@李子宁
Happy,happy everyday!
冲鸭！
*/

import com.interview.javabasic.DataStructrue.MIGong;
import com.interview.javabasic.DataStructrue.graph.Graph;

import java.util.*;

public class getMaxK {
    static String LOWER = "abcdefghijklmnopqrstuvwxyz";
    static String[] singleNum = {"zero","one","two","three","four","five","six","seven","eight","nine"};
    static String[] douNum = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
    static String[] indexNum = {"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
    static List<String> list = new ArrayList<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] arr = new int[n+2][m+2];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                arr[i][j] = in.nextInt();
            }
        }
        for (int i = 0; i <= n+1; i++) {
            arr[i][0] = 1;
            arr[i][m+1] = 1;
        }
        for (int i = 0; i <= m+1; i++) {
            arr[0][i] = 1;
            arr[n+1][i] = 1;
        }
        MiGong(arr,1,1);
        for (int i = list.size()-1; i >=0; i--) {
            System.out.println(list.get(i));
        }
    }
//迷宫问题，回溯法解决
    public static boolean MiGong(int[][] arr,int i,int j){
        if (arr[arr.length-2][arr[0].length-2]==2){
            return true;
        }else {
                if (arr[i][j] == 0){
                    arr[i][j] = 2;
                    if (MiGong(arr,i+1,j)){
                        list.add("("+(i-1)+","+(j-1)+")");
                        System.out.println();
                        return true;
                    }else if (MiGong(arr,i,j+1)){
                       list.add("("+(i-1)+","+(j-1)+")");
                        return true;
                    }else if(MiGong(arr,i,j-1)){
                       list.add("("+(i-1)+","+(j-1)+")");
                        return true;
                    }else if (MiGong(arr,i-1,j)){
                       list.add("("+(i-1)+","+(j-1)+")");
                        return true;
                    }else {
                        arr[i][j] = 3;
                        return false;
                    }
                }else{
                    return false;
                }
        }
    }

    public static String parse(long num){
        String s = num+"";
        char[] chars = s.toCharArray();
        int len = chars.length;

        if (len==1){
            System.out.println(singleNum[chars[0]-'0']);
        }else if (len==2){

        }else if (len==3){
            System.out.println(thirdIndex(chars));
        }else if (len==4){
            System.out.println(fourindex(chars));
        }else if (len>4&&len<7){
            String tmp = chars.toString();
            if (len==5){
                char[] c1 = tmp.substring(0,2).toCharArray();
                System.out.println();
            }
        }

        return chars[0]+"";
    }
    public static String fourindex(char[] chars){
        String tmp = chars.toString();
        char[] chars1 = tmp.substring(tmp.length() - 3).toCharArray();
       return singleNum[chars[0]-'0']+" throusand "+thirdIndex(chars1);
    }
    public static String thirdIndex(char[] chars){
        char[] chars1 = {chars[1],chars[2]};
        return singleNum[chars[0]-'0']+" hundred and "+doubleIndex(chars1);
    }
    public static String doubleIndex(char[] chars){
        String s = "";
        if (chars[0]=='1'){
            s = douNum[chars[1]-'0'];
        }else if (chars[1]=='0'){
            s = indexNum[chars[0]-'0'];
        }else{
            s = indexNum[chars[0]-'0']+" "+singleNum[chars[1]-'0'];
        }
        return s;
    }
    //用砝码称重
    public static int fama(int n, int[] weight, int[] nums){
        Set<Integer> set = new HashSet<>();
        for(int i=0;i<=nums[0];i++)
            set.add(i*weight[0]);
        for(int i=1;i<n;i++){//从第二个砝码开始
            List<Integer>list =new ArrayList<Integer>(set);
            for(int j=1;j<=nums[i];j++){//遍历砝码的个数
                for(int k=0;k<list.size();k++)
                    set.add(list.get(k)+j*weight[i]);
            }
        }
        return set.size();
    }

    /**
     * 统计出英文字母字符的个数。
     *
     * @param str 需要输入的字符串
     * @return 英文字母的个数
     */
    public static int getEnglishCharCount(String str)
    {
        int res = 0;
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            if (((int)aChar>=97&&(int)aChar<=122)||((int)aChar>=65&&(int)aChar<=90)){
                res++;
            }
        }
        return res;
    }

    /**
     * 统计出空格字符的个数。
     *
     * @param str 需要输入的字符串
     * @return 空格的个数
     */
    public static int getBlankCharCount(String str)
    {
        int res = 0;
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            if ((int)aChar==32){
                res++;
            }
        }
        return res;
    }

    /**
     * 统计出数字字符的个数。
     *
     * @param str 需要输入的字符串
     * @return 英文字母的个数
     */
    public static int getNumberCharCount(String str)
    {
        int res = 0;
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            if ((int)aChar>=48&&(int)aChar<=57){
                res++;
            }
        }
        return res;
    }

    /**
     * 统计出其它字符的个数。
     *
     * @param str 需要输入的字符串
     * @return 英文字母的个数
     */
    public static int getOtherCharCount(String str)
    {
        int res = 0;
        char[] chars = str.toCharArray();
        for (char aChar : chars) {
            if (!(((int)aChar>=48&&(int)aChar<=57)||(int)aChar==32||((int)aChar>=97&&(int)aChar<=122)||((int)aChar>=65&&(int)aChar<=90))){
                res++;
            }
        }
        return res;
    }


    //斐波那契数列查询
    public static int fibnacc(int n){
        int[] f = new int[n];
        f[1] = 1;
        f[2] = 2;
        for (int i = 3; i < n; i++) {
            f[i] = f[i-1]+f[i-2];
        }
        return f[n-1];
    }
    //密文的加密解密,char<=90就是大写，
    public static void passToUpass(char[] pass,char[] key){
        StringBuilder stringBuilder = new StringBuilder();
        Set<String> set = new LinkedHashSet<>();
        for (int i = 0; i < pass.length; i++) {
            set.add((pass[i]+"").toLowerCase());
        }
        for (int i = 0; i < LOWER.length(); i++) {
            set.add(LOWER.charAt(i)+"");
        }
        List<String> ob = new ArrayList<>(set);
        for (int i = 0; i < key.length; i++) {
            String k = key[i] <=90 ? ob.get(key[i] - 'A').toLowerCase() :ob.get(key[i] - 'a');
            stringBuilder.append(k);
        }
        System.out.println(stringBuilder.toString());
    }
    //输出蛇形数组
    public static void GetResult(int num){
        int[][] arr = new int[num][num];
        arr[0][0] = 1;
        for (int i = 0,k = 2; i < num; i++) {
            if (i == 0){
                arr[i][0] = 1;
            }else {
                arr[i][0] = arr[i-1][0] + i;
            }
            int tmp = k;
            for (int j = 1; j < num; j++) {
                arr[i][j] = arr[i][j-1] + tmp;
                tmp++;
            }
            k++;
        }
        //输出蛇形数组
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < num - i; j++) {
                System.out.print(arr[i][j]+ " ");
            }
            System.out.println();
        }

    }

    //IP与十进制的数字相互换换：例如：10.0.3.193=>167969729
    public static long IPToNum(String s){
        String[] arr = s.split("\\.");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            int k = Long.toBinaryString( Long.parseLong(arr[i])).length();
            while (k<8){
                sb.append(0);
                k++;
            }
            sb.append(Long.toBinaryString( Long.parseLong(arr[i])));
        }
        /*long n=Long.parseLong(arr[0]);

        for(int i=1;i<arr.length;i++){
            n=n<<8;
            n=n+Long.parseLong(arr[i]);
        }
        return n;*/
        return Long.parseLong(sb.toString(),2);
    }
    public static String NumToIP(String num){
        long nums = Long.parseLong(num);
        String s = Long.toBinaryString(nums);
        StringBuilder stringBuilder = new StringBuilder();
        int k = s.length();
        while (32-k>0){
            s = 0 + s;
            k++;
        }
        for (int i = 0; i < s.length()-7; i+=8) {
            stringBuilder.append(Integer.parseInt(s.substring(i,i+8),2));
            if (i!=24){
                stringBuilder.append(".");
            }
        }
        return stringBuilder.toString();
    }

    //求最大回文数
    public static int maxReverse(String s) {
        int count = 0;
        char[] chars = s.toCharArray();
        ArrayList<Character> list = new ArrayList<>();
        list.add('#');
        int left = 0;
        int right = 0;
        int tmp= 0 ;
        for (int i = 0; i < chars.length; i++) {
           list.add(chars[i]);
           list.add('#');
        }
        int[] mlen = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            left = i-1;
            right = i + 1;
            while (left >=0 && right <=list.size()-1){
                if (list.get(left) == list.get(right)){
                    tmp++;
                    left--;
                    right++;
                }else{
                    left = -1;
                }
            }
            count = tmp>count?tmp:count;
            tmp = 0;
        }
        return count;
    }

    //冒泡排序
    public static void bubble(int[] arr){
        int tmp = 0;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1 - i; j++) {
                if (arr[j] - arr[j+1] < 0){
                    tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
    }
    public static void bubble(char[] arr){
        char tmp;
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1 - i; j++) {
                if (arr[j] - arr[j+1] > 0){
                    tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
    }

    //超长两个正整数的加法
    public static String AddLongInteger(String addend, String augend) {
       StringBuilder sb = new StringBuilder();
        char[] add = addend.toCharArray();
        char[] aug = augend.toCharArray();
        int len1 = add.length - 1;
        int len2 = aug.length - 1;
        int flag = -1;
        while (len1>= 0 && len2 >=0){
            int tmp1 = add[len1] - '0';
            int tmp2= aug[len2] - '0';
            int result = flag == -1? tmp1+tmp2:tmp1 + tmp2 + flag;
            if (result>=10){
                sb.append(String.valueOf(result%10));
                flag = result/10;
            }else {
                sb.append(String.valueOf(result));
                flag = -1;
            }
            len1--;
            len2--;
        }
        while (len1 >= 0){
            int tmp = add[len1] - '0';
            int results = flag == -1?tmp:tmp + flag;
            if (results >= 10){
                sb.append(String.valueOf(results%10));
                flag = results/10;
            }else {
                sb.append(String.valueOf(results));
                flag = -1;
            }
            len1--;
        }

        while (len2 >= 0){
            int tmp = aug[len2] - '0';
            int results = flag == -1?tmp:tmp + flag;
            if (results >= 10){
                sb.append(String.valueOf(results%10));
                flag = results/10;
            }else {
                sb.append(String.valueOf(results));
                flag = -1;
            }
            len2--;
        }
        if (flag !=-1){
            sb.append(flag);
        }
        return sb.reverse().toString();
    }



}
